package algotrader.gui;

import javax.swing.table.AbstractTableModel;

import algotrader.book.Book;

public class BookTableModel extends AbstractTableModel {
	
	private static final long serialVersionUID = 1L;
	private Book book;
	
	public BookTableModel(Book book) {
		this.book = book; 
	}
	
	@Override
	public int getColumnCount() {
		return 6;
	}

	@Override
	public int getRowCount() {
		if(book.getCompraBookLines().size() > book.getVendaBookLines().size())
			return book.getCompraBookLines().size();
		else 
			return book.getVendaBookLines().size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		try {
			if(col == 0) return book.getCompraBookLines().get(row).getCorretora();
			else if (col == 1) return book.getCompraBookLines().get(row).getQuantidade();
			else if (col == 2) return book.getCompraBookLines().get(row).getPreco();
			else if (col == 3) return book.getVendaBookLines().get(row).getPreco();
			else if (col == 4) return book.getVendaBookLines().get(row).getQuantidade();
			else if (col == 5) return book.getVendaBookLines().get(row).getCorretora();
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public String getColumnName(int col) {
		if (col == 0)
			return "Cr.";
		else if (col == 1)
			return "Qtd.";
		else if (col == 2)
			return "Cpa.";
		else if (col == 3) 
			return "Vda.";
		else if (col == 4) 
			return "Qtd.";
		else if (col == 5) 
			return "Cor.";
		return "";
	}
}
